package com.yiyahui.project.erp.controller;

import java.util.List;

import com.yiyahui.project.erp.domain.requestVo.PayMoneyRequest;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import com.yiyahui.framework.aspectj.lang.annotation.Log;
import com.yiyahui.framework.aspectj.lang.enums.BusinessType;
import com.yiyahui.project.erp.domain.YiyaClosingMethods;
import com.yiyahui.project.erp.service.IYiyaClosingMethodsService;
import com.yiyahui.framework.web.controller.BaseController;
import com.yiyahui.framework.web.domain.AjaxResult;
import com.yiyahui.common.utils.poi.ExcelUtil;
import com.yiyahui.framework.web.page.TableDataInfo;

/**
 * 主单结账流水方式Controller
 * 
 * @author yiyahui
 * @date 2020-06-10
 */
@Api("主单结账流水方式")
@RestController
@RequestMapping("/erp/methods")
public class YiyaClosingMethodsController extends BaseController
{
    @Autowired
    private IYiyaClosingMethodsService yiyaClosingMethodsService;

    /**
     * 查询主单结账流水方式列表
     */
    @ApiOperation("查询主单结账流水方式列表")
    @PreAuthorize("@ss.hasPermi('erp:methods:list')")
    @GetMapping("/list")
    public TableDataInfo list(YiyaClosingMethods yiyaClosingMethods)
    {
        startPage();
        List<YiyaClosingMethods> list = yiyaClosingMethodsService.selectYiyaClosingMethodsList(yiyaClosingMethods);
        return getDataTable(list);
    }

    /**
     * 导出主单结账流水方式列表
     */
    @ApiOperation("导出主单结账流水方式列表")
    @PreAuthorize("@ss.hasPermi('erp:methods:export')")
    @Log(title = "主单结账流水方式", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(YiyaClosingMethods yiyaClosingMethods)
    {
        List<YiyaClosingMethods> list = yiyaClosingMethodsService.selectYiyaClosingMethodsList(yiyaClosingMethods);
        ExcelUtil<YiyaClosingMethods> util = new ExcelUtil<YiyaClosingMethods>(YiyaClosingMethods.class);
        return util.exportExcel(list, "methods");
    }

    /**
     * 获取主单结账流水方式详细信息
     */
    @ApiOperation("获取主单结账流水方式详细信息")
    @ApiImplicitParam(name = "id", value = "主键id", required = true, dataType = "Long", paramType = "path")
    @PreAuthorize("@ss.hasPermi('erp:methods:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(yiyaClosingMethodsService.selectYiyaClosingMethodsById(id));
    }

    /**
     * 新增主单结账流水方式
     */
    @ApiOperation("新增主单结账流水方式")
    @ApiImplicitParam(name = "yiyaClosingMethods", value = "${tableComment}", dataType = "YiyaClosingMethods")
    @PreAuthorize("@ss.hasPermi('erp:methods:add')")
    @Log(title = "主单结账流水方式", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YiyaClosingMethods yiyaClosingMethods)
    {
        return toAjax(yiyaClosingMethodsService.insertYiyaClosingMethods(yiyaClosingMethods));
    }

    /**
     * 修改主单结账流水方式
     */
    @ApiOperation("修改主单结账流水方式")
    @ApiImplicitParam(name = "yiyaClosingMethods", value = "${tableComment}", dataType = "YiyaClosingMethods")
    @PreAuthorize("@ss.hasPermi('erp:methods:edit')")
    @Log(title = "主单结账流水方式", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YiyaClosingMethods yiyaClosingMethods)
    {
        return toAjax(yiyaClosingMethodsService.updateYiyaClosingMethods(yiyaClosingMethods));
    }

    /**
     * 删除主单结账流水方式
     */
    @ApiOperation("删除主单结账流水方式")
    @ApiImplicitParam(name = "ids", value = "主键id数组", required = true, dataType = "Long[]", paramType = "path")
    @PreAuthorize("@ss.hasPermi('erp:methods:remove')")
    @Log(title = "主单结账流水方式", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yiyaClosingMethodsService.deleteYiyaClosingMethodsByIds(ids));
    }


    /**
     * 缴费
     */
    @ApiOperation("缴费")
    @Log(title = "缴费", businessType = BusinessType.INSERT)
    @PostMapping("/pay/money")
    public AjaxResult payMoney(@RequestBody PayMoneyRequest payMoneyRequest)
    {
        try {
            return yiyaClosingMethodsService.payMoney(payMoneyRequest);
        } catch (Exception e) {
            logger.error(e.getMessage());
            return AjaxResult.error();
        }
    }
}
